<script setup>
import { ref } from 'vue'
import { useAppStore, useCoreStore, insStoreRefsArray } from '@/stores'
import $router from '@/router'
const [[appStore], [coreStore]] = insStoreRefsArray([useAppStore, useCoreStore])

// const formSchema = ref({
//   fields: [
//     {
//       label: '',
//       name: 'un',
//       as: 'InputText',
//       class: 'w-24rem h-3rem',
//       placeholder: 'placeholder',
//       rules: yup.string().required().email()
//     },
//     {
//       label: '',
//       name: 'pwd',
//       feedbadk: false,
//       as: 'Password',
//       class: 'w-24rem h-3rem',
//       rules: yup.string().required()
//     }
//   ]
// })

const ref_form = ref()
const login_form = ref({ un: '', pwd: '' })
function onSubmit() {
  // ref_form.submit()
  appStore.login(login_form.value).then((resp) => {
    const {
      data: {
        success,
        list: { data, token }
      }
    } = resp

    if (success) {
      appStore.msg.success('登录成功')
      $router.replace('/')
      setTimeout(() => {
        location.reload()
      }, 2000)
    } else {
      appStore.msg.error('登录失败')
    }
    console.log('data', data, 'token', token)
  })
}
</script>
<template>
  <div
    class="flex flex-column justify-content-center align-items-center bg-primary"
    style="height: 65vh"
  >
    <form action="" :ref="ref_form">
      <div class="flex flex-column align-items-center p-5 gap-4 shadow-sm pb-8 bg-white shadow-3">
        <span class="text-center text-primary text-4xl border-bottom-2 border-primary-500 my-3"
          >平台登录</span
        >
        <InputGroup>
          <InputGroupAddon>
            <i class="pi pi-user"></i>
          </InputGroupAddon>
          <InputText
            placeholder="请输入用户名"
            type="text"
            v-model="login_form.un"
            required=""
            size="large"
            class="w-24rem"
          />
        </InputGroup>

        <InputGroup>
          <InputGroupAddon>
            <i class="pi pi-lock"></i>
          </InputGroupAddon>
          <InputText
            placeholder="请输入密码"
            v-model="login_form.pwd"
            required=""
            size="large"
            type="password"
            class="w-24rem"
          />
        </InputGroup>

        <div class="w-full flex flex-column align-content-center gap-2">
          <Button label="登录" @click="onSubmit()" size="large" />
          <Button label="注册" outlined="" size="large" />
        </div>
      </div>
    </form>
    <!-- <DynamicForm
      class="flex flex-column border p-4 w-80"
      :schema="formSchema"
      :formdata="formData"
      :submit="onSubmit"
      :submitProp="{ label: '登陆', class: 'w-full' }"
    /> -->
  </div>
</template>
<style scoped>
:deep(input) {
  width: 100%;
}
</style>
